package com.xinqi.modules.course.clazz.factory;

import com.xinqi.common.base.error.CommonErrors;
import com.xinqi.common.base.response.R;
import com.xinqi.common.rocketmq.dto.CourseClassMessageBody;
import com.xinqi.modules.course.clazz.client.ClassClient;
import com.xinqi.modules.course.clazz.dto.rsp.ClassResultDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 班级降级处理
 *
 * @author: system
 * @date: 2023/01/12
 */
@Slf4j
@Component
public class ClassFallbackFactory implements FallbackFactory<ClassClient> {

    @Override
    public ClassClient create(Throwable throwable) {
        log.error("课程服务调用失败:{}", throwable.getMessage());
        return new ClassClient() {

            @Override
            public R<Void> processingClass(CourseClassMessageBody body) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<ClassResultDTO> findClass(Long classId) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<List<ClassResultDTO>> findAllClass() {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }
        };
    }
}
